import PySimpleGUI as sg

"""
    Demo - Custom Checkboxes done simply

    The Base64 Image encoding feature of PySimpleGUI makes it possible to create beautiful GUIs very simply
    
    These 2 checkboxes required 3 extra lines of code than a normal checkbox.  
    1. Keep track of the current value using the Image Element's Metadata
    2. Changle / Update the image when clicked
    3. The Base64 image definition
    
    Enable the event on the Image with the checkbox so that you can take action (flip the value)

    Copyright 2022-2023 PySimpleSoft, Inc. and/or its licensors. All rights reserved.
    
    Redistribution, modification, or any other use of PySimpleGUI or any portion thereof is subject to the terms of the PySimpleGUI License Agreement available at https://eula.pysimplegui.com.
    
    You may not redistribute, modify or otherwise use PySimpleGUI or its contents except pursuant to the PySimpleGUI License Agreement.
"""

def main():
    layout = [[sg.Text('Fancy Checkboxes... Simply')],
              [sg.Image(checked, key=('-IMAGE-', 1), metadata=True, enable_events=True), sg.Text(True, enable_events=True, k=('-TEXT-', 1))],
              [sg.Image(unchecked, key=('-IMAGE-', 2), metadata=False, enable_events=True), sg.Text(False, enable_events=True, k=('-TEXT-', 2))],
              [sg.Button('Go'), sg.Button('Exit')]]

    window = sg.Window('Custom Checkboxes', layout, font="_ 14")
    while True:
        event, values = window.read()
        print(event, values)
        if event == sg.WIN_CLOSED or event == 'Exit':
            break
        # if a checkbox is clicked, flip the vale and the image
        if event[0] in ('-IMAGE-', '-TEXT-'):
            cbox_key = ('-IMAGE-', event[1])
            text_key = ('-TEXT-', event[1])
            window[cbox_key].metadata = not window[cbox_key].metadata
            window[cbox_key].update(checked if window[cbox_key].metadata else unchecked)
            # Update the string next to the checkbox
            window[text_key].update(window[cbox_key].metadata)

    window.close()


if __name__ == '__main__':
    checked = b'iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAKMGlDQ1BJQ0MgUHJvZmlsZQAAeJydlndUVNcWh8+9d3qhzTAUKUPvvQ0gvTep0kRhmBlgKAMOMzSxIaICEUVEBBVBgiIGjIYisSKKhYBgwR6QIKDEYBRRUXkzslZ05eW9l5ffH2d9a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